﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Runtime.Serialization;

namespace DBMS.Models
{
     [Serializable()]
    public class Relationship : ISerializable
    {
        public int Index { get; set; }

        public Table PrimaryTable { get; set; }

        public int PrimaryTableId { get; set; }

        public Column PrimaryColumn { get; set; }

        public int PrimaryColumnId { get; set; }

        public Table ForeignTable { get; set; }

        public int ForeignTableId { get; set; }

        public Column ForeignColumn { get; set; }

        public int ForeignColumnId { get; set; }

        public bool Deleted { get; set; }

        public Relationship() { }

        public Relationship(SerializationInfo info, StreamingContext ctxt)
        {
            this.Index = (int)info.GetValue("Index", typeof(int));
            this.PrimaryTableId = (int)info.GetValue("PrimaryTableId", typeof(int));
            this.ForeignTableId = (int)info.GetValue("ForeignTableId", typeof(int));
            this.PrimaryColumnId = (int)info.GetValue("PrimaryColumnId", typeof(int));
            this.ForeignColumnId = (int)info.GetValue("ForeignColumnId", typeof(int));
            this.Deleted = (bool)info.GetValue("Deleted", typeof(bool));
        }

        public void GetObjectData(SerializationInfo info, StreamingContext ctxt)
        {
            info.AddValue("Index", this.Index);
            info.AddValue("PrimaryTableId", this.PrimaryTableId);
            info.AddValue("ForeignTableId", this.ForeignTableId);
            info.AddValue("PrimaryColumnId", this.PrimaryColumnId);
            info.AddValue("ForeignColumnId", this.ForeignColumnId);
            info.AddValue("Deleted", this.Deleted);
        }
    }
}